# 股票客户流失逻辑线性回归

import numpy as np
import pandas as pd
from LogisticRegression import LogisticRegression


lr = LogisticRegression()
# 读取数据集
data = pd.read_excel('/Users/liuyuanxi/学习/华为智能基座/附件2.课程资源/数据集/股票客户流失.xlsx', skipfooter = 5043)
print(data, "\n共 %d 条数据"%(len(data)))
# 划分数据
data = pd.read_excel('/Users/liuyuanxi/学习/华为智能基座/附件2.课程资源/数据集/股票客户流失.xlsx', skipfooter = 5043, usecols = [0, 1, 2, 3, 4])
x_train = np.array(data)
# 寻找每一列最大的数进行归一化
for i in range(5):
    biggestNum = 0 # 初始化最大值
    for j in range(int(len(x_train))):
        if x_train[j][i] > biggestNum:
            biggestNum = x_train[j][i]
        else:
            continue
    for k in range(int(len(x_train))):
        x_train[k][i] = x_train[k][i]/biggestNum # 归一化
data = pd.read_excel('/Users/liuyuanxi/学习/华为智能基座/附件2.课程资源/数据集/股票客户流失.xlsx', skipfooter = 5043,  usecols = [5])
y_train = np.array(data)
# 归一化输出结果
biggestNum = 0 # 初始化最大值
for i in range(int(len(y_train))):
    if y_train[i] > biggestNum:
        biggestNum = y_train[i]
    else:
        continue
for i in range(int(len(y_train))):
    y_train[i] = y_train[i]/biggestNum # 归一化
print("正在训练模型，请等待...\n")
GDFit_loss_list = lr.GD_Fit(x_train, y_train, 0.01, 2000)
SGDFit_loss_list = lr.SGD_Fit(x_train, y_train, 0.01, 1)
# 训练过程可视化
lr.training_visualize(GDFit_loss_list, SGDFit_loss_list)
